package com.example.w0407;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends Activity {
    private  ListView mListView;
    private  String[] titles={"武文博，热爱计科" ,"考研自习室" ,"毕业照","博书苑北" };
    private  String[] sources={"无锡风景 ","汇锦校园 ","思华年摄影 ","汇一方工作室 "};
    private  String[] times={"2022-04-05","2022-04-06","2022-04-07","2022-04-09"};
    private  int[] images={R.drawable.z1,R.drawable.z2,R.drawable.z3,R.drawable.z4};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mListView = (ListView) findViewById(R.id.lv);
        MyBaseAdapter mAdapter = new MyBaseAdapter();
        mListView.setAdapter(mAdapter);
    }

    class  MyBaseAdapter extends BaseAdapter{

        @Override
        public int getCount() {

            return titles.length;
        }

        @Override
        public Object getItem(int i) {

            return titles[i];
        }

        @Override
        public long getItemId(int i) {

            return i;
        }

        @Override
        public View getView(int i, View convertView, ViewGroup viewGroup) {
            View view = View.inflate(MainActivity.this, R.layout.list_item, null);

            TextView title = view.findViewById(R.id.title);
            TextView source = view.findViewById(R.id.source);
            TextView time=view.findViewById(R.id.time);
            ImageView iv=view.findViewById(R.id.iv);

            title.setText(titles[i]);
            source.setText(sources[i]);
            time.setText(times[i]);
            iv.setBackgroundResource(images[i]);

            return view;
        }

    }
}